import axios from 'axios'; // 引入axios
import QS from 'qs'; // 引入qs模块

const service = axios.create({
    baseURL: 'http://192.168.0.121:5080/jkf', // api 的 base_url
    timeout: 5000, // request timeout  设置请求超时时间
    responseType: "json",
    //withCredentials: true, // 是否允许带cookie这些
    headers: {
        "Content-Type": "application/json;charset=utf-8"
    }
});
/**
 * get方法，对应get请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
 export function get(url, params){
    return new Promise((resolve, reject) =>{
        service.get(url, {
            params: params
        }).then(res => {
            resolve(res.data);
        }).catch(err =>{
            reject(err.data)
    })
});}
/**
 * post方法，对应post请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
 export function post(url, params) {
    return new Promise((resolve, reject) => {
        //var tmp = QS.stringify(params);
        service.post(url, params)
        .then(res => {
            resolve(res.data);
        })
        .catch(err =>{
            reject(err.data)
        })
    });
}

export function _delete(url, params){
    return new Promise((resolve,reject)=>{
        service.delete(url,params).then(res=>{
            resolve(res.data);
        }).catch(e=>{
            reject(err.data);
        });
    });
}

